package com.log4jviewer.ui.preferences;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.log4jviewer.ui.preferences.additional.LogDisplayPreferences;
import com.log4jviewer.ui.preferences.additional.LogFieldColumn;

/**
 * Class initializes default preferences in the entrance store.
 * 
 * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
 */
public class DefaultPreferenceInitializer {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    public void initializeDefaultPreferences(final IPreferenceStore store) {
        // Set default server settings
        store.setDefault(ServerPreferences.getId(), ServerPreferences.getDefaultPreferences());
        logger.debug("Default settings for Server were initialized");

        // Set default log file settings
        store.setDefault(DefaultPreferences.LogFilePreferences.getId(),
                DefaultPreferences.LogFilePreferences.getDefaultPreferences());
        logger.debug("Default settings for Log File were initialized");

        // Set default LogView settings (output limitation)
        store.setDefault(DefaultPreferences.LogViewPreferences.getId(),
                DefaultPreferences.LogViewPreferences.getDefaultPreferences());
        logger.debug("Default settings for LogView were initialized");

        // Set default level display settings
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Foreground.DEBUG_COLOR.getId(),
                LogDisplayPreferences.Foreground.DEBUG_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Foreground.INFO_COLOR.getId(),
                LogDisplayPreferences.Foreground.INFO_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Foreground.WARN_COLOR.getId(),
                LogDisplayPreferences.Foreground.WARN_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Foreground.ERROR_COLOR.getId(),
                LogDisplayPreferences.Foreground.WARN_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Foreground.FATAL_COLOR.getId(),
                LogDisplayPreferences.Foreground.FATAL_COLOR.getDefaultColor());

        PreferenceConverter.setDefault(store, LogDisplayPreferences.Background.DEBUG_COLOR.getId(),
                LogDisplayPreferences.Background.DEBUG_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Background.INFO_COLOR.getId(),
                LogDisplayPreferences.Background.INFO_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Background.WARN_COLOR.getId(),
                LogDisplayPreferences.Background.WARN_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Background.ERROR_COLOR.getId(),
                LogDisplayPreferences.Background.WARN_COLOR.getDefaultColor());
        PreferenceConverter.setDefault(store, LogDisplayPreferences.Background.FATAL_COLOR.getId(),
                LogDisplayPreferences.Background.FATAL_COLOR.getDefaultColor());

        store.setDefault(LogDisplayPreferences.getLogColorSettings().getId(), LogDisplayPreferences
                .getLogColorSettings().getDefault());
        store.setDefault(LogDisplayPreferences.getLogFontSettings().getId(), LogDisplayPreferences
                .getLogFontSettings().getDefault());
        logger.debug("Default log display settings were initialized");

        // Set default table columns settings
        store.setDefault(LogFieldColumn.LEVEL_COLUMN.getId(), LogFieldColumn.LEVEL_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.CATEGORY_COLUMN.getId(), LogFieldColumn.CATEGORY_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.MESSAGE_COLUMN.getId(), LogFieldColumn.MESSAGE_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.LINE_COLUMN.getId(), LogFieldColumn.LINE_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.DATE_COLUMN.getId(), LogFieldColumn.DATE_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.NDC_COLUMN.getId(), LogFieldColumn.NDC_COLUMN.getDefaultPrefs());
        store.setDefault(LogFieldColumn.THROWABLE_COLUMN.getId(), LogFieldColumn.THROWABLE_COLUMN.getDefaultPrefs());
        logger.debug("Default settings for LogView table columns were initialized");

        // Set default log file settings
        store.setDefault(DefaultPreferences.FilterPreferences.getId(),
                DefaultPreferences.FilterPreferences.getDefaultPreferences());
        logger.debug("Default settings for active filter were initialized");
    }
}
